var a = getApp();

Page({
    data: {
        radUrl: "../../img/radn.png",
        inshow: !0,
        className: "check",
        baseUrl: a.globalData.baseUrl,
        totalPay: "",
        otherPay: "",
        couponId: "",
        redSum: ""
    },
    onLoad: function(t) {
        var e = this;
        e.setData({
            storeId: a.globalData.storeId,
            couponId: a.globalData.couponId
        }), wx.request({
            url: a.globalData.baseUrl + a.globalData.urlStoreDetail,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                storeId: a.globalData.storeId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : e.setData({
                    store: t.data
                });
            }
        });
    },
    getTotalValue: function(a) {
        this.setData({
            totalPay: a.detail.value
        });
    },
    getOtherValue: function(a) {
        this.setData({
            otherPay: a.detail.value
        });
    },
    choSum: function(a) {
        var t = this;
        a.currentTarget.dataset.classname.match(".*checkon.*") ? t.setData({
            radUrl: "../../img/radn.png",
            inshow: !0,
            className: "check"
        }) : t.setData({
            radUrl: "../../img/radh.png",
            inshow: !1,
            className: "check checkon"
        });
    },
    redPacket: function(a) {
        wx.navigateTo({
            url: "redPackets"
        });
    },
    checkOrder: function() {
        var t = this;
        wx.request({
            url: a.globalData.baseUrl + a.globalData.urlAddNormalOrder,
            data: {
                userId: a.globalData.userId,
                couponId: a.globalData.couponId,
                totalPay: t.data.totalPay,
                otherPay: t.data.otherPay,
                storeId: a.globalData.storeId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                0 != e.code ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }) : t.getPayData(e.msg);
            }
        });
    },
    cStore: function() {
        wx.navigateTo({
            url: "../storeList/storeList?page=md"
        });
    },
    onShow: function() {
        var t = this, e = getCurrentPages(), o = e[e.length - 1];
        t.setData({
            redSum: o.data.redSum,
            couponId: a.globalData.couponId
        });
    },
    getPayData: function(t) {
        var e = this, o = a.globalData.urlBase + a.globalData.urlPayData;
        wx.request({
            url: o,
            data: {
                orderId: t,
                userId: a.globalData.userId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : e.wxPay(t);
            }
        });
    },
    wxPay: function(t) {
        var e = this;
        wx.requestPayment({
            timeStamp: t.timeStamp,
            nonceStr: t.nonceStr,
            package: "prepay_id=" + t.totalId,
            signType: "MD5",
            paySign: t.sign,
            success: function(a) {
                e.setData({
                    page: 1,
                    limit: 20,
                    orderList: []
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: "支付失败",
                    icon: "none",
                    duration: 2e3
                });
            },
            complete: function(t) {
                e.setData({
                    redSum: "",
                    couponId: "",
                    otherPay: "",
                    totalPay: ""
                }), a.globalData.couponId = "";
            }
        });
    },
    onShareAppMessage: function() {}
});